package com.ruoyi.web.controller.bussiness;

import cn.dev33.satoken.stp.StpUtil;
import com.ruoyi.bussiness.domain.*;
import com.ruoyi.bussiness.mapper.TAppUserMapper;
import com.ruoyi.bussiness.service.ITAiFollowOrdersService;
import com.ruoyi.bussiness.service.ITAiInvestorProfilesService;
import com.ruoyi.bussiness.service.ITAiProductCategoriesService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/api/aifollow")
public class TAiFollowController extends BaseController {

    // 产品分类
    @Autowired
    private ITAiProductCategoriesService aiProductCategoriesService;

    // 投资人信息
    @Autowired
    private ITAiInvestorProfilesService tAiInvestorProfilesService;

    // 跟投订单
    @Autowired
    private ITAiFollowOrdersService tAiFollowOrdersService;

    @Resource
    private TAppUserMapper appUserMapper;

    /**
     * 查询产品分类（中英文）列表
     */
    @GetMapping("/selectproductlist")
    public AjaxResult list(TAiProductCategories tAiContractConfig)
    {
//        startPage();
        List<TAiProductCategories> list = aiProductCategoriesService.selectTAiProductCategoriesList(tAiContractConfig);
//        return getDataTable
        return AjaxResult.success(list);
    }

    /**
     * 查询投资人管理列表
     */
    @GetMapping("/selectinvestlist")
    public AjaxResult list(TAiInvestorProfiles tAiInvestorProfiles)
    {
//        startPage();
        List<TAiInvestorProfiles> list = tAiInvestorProfilesService.selectTAiInvestorProfilesList(tAiInvestorProfiles);
        return AjaxResult.success(list);
    }

    /**
     * 查询投资人详细信息
     */
    @GetMapping("/getinvestinfo")
    public AjaxResult getInfo(String id) {
        return AjaxResult.success(tAiInvestorProfilesService.selectTAiInvestorProfilesById(id));
    }

    /**
     * 查询跟投订单列表
     */
    @GetMapping("/getfolloworderlist")
    public AjaxResult list(TAiFollowOrders tAiFollowOrders)
    {
        long loginIdAsLong = StpUtil.getLoginIdAsLong();
        TAppUser user = appUserMapper.selectTAppUserByUserId(loginIdAsLong);
        tAiFollowOrders.setUserId(user.getUserId().toString());
        List<TAiFollowOrders> list = tAiFollowOrdersService.selectTAiFollowOrdersList(tAiFollowOrders);
        return AjaxResult.success(list);
    }

    /**
     * 获取跟投订单详细信息
     */
    @GetMapping(value = "/getfolloworderinfo")
    public AjaxResult getFollowOrderInfo(String id)
    {
        return AjaxResult.success(tAiFollowOrdersService.selectTAiFollowOrdersById(id));
    }

    /**
     * 新增跟投订单
     */
    @PostMapping("createfolloworder")
    public AjaxResult add(@RequestBody TAiFollowOrders tAiFollowOrders)
    {
        return AjaxResult.success(tAiFollowOrdersService.createFollowOrder(tAiFollowOrders));
    }
}
